import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import { prismjsPlugin } from "vite-plugin-prismjs";

export default ({ mode }) => {
  const env = loadEnv(mode, "./");

  const baseAPI = env.VITE_BASE_API;
  const proxyAPI = env.VITE_PROXY_API;

  return defineConfig({
    plugins: [
      vue(),
      prismjsPlugin({
        languages: "all"
      }),
    ],
    resolve: {
      alias: {
        "@": "/src",
      },
    },
    server: {
      host: true,
      port: Number(env.VITE_PORT) || 5173,
      proxy: {
        [baseAPI]: {
          target: proxyAPI,
          changeOrigin: true,
          rewrite: (path) => path.replace(new RegExp(`^${baseAPI}`), ""),
        },
      },
    },
  });
};
